﻿using MediatR;
using Traceability.Commont.Domains.ScratchTheFat;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;
using Yitter.IdGenerator;
namespace U.Enterprise.Api.Applications.PartitionWarehousings
{
    public class SplitRUCreateHandler : IRequestHandler<SplitRUCreateCommond, Resqults>
    {
        private readonly IBateRepository<SplitRU> _SplitRU;

        public SplitRUCreateHandler(IBateRepository<SplitRU> splitRU
            )
        {
            _SplitRU = splitRU;
        }

        public async Task<Resqults> Handle(SplitRUCreateCommond request, CancellationToken cancellationToken)
        {
            var list = new Resqults() { Code = 0 };

            var query = new SplitRU()
            {
                ShoppIngId = request.ShoppIngId,
                Stoct = request.Stoct,
                DocumentNo =YitIdHelper.NextId().ToString(),
                DocumentsDate = DateTime.Now,
                RepositoryID = request.RepositoryID,
                ScaleId=request.ScaleId,
                WeightNum=request.WeightNum,
                GrossWeight=request.GrossWeight,
                Tare=request.Tare,
                NetWeight=request.NetWeight,
            };
            var hb =await _SplitRU.Add(query);
            list.Code = hb;
            return list;

        }
    }
}
